<?php
class SiteCommand extends CConsoleCommand
{
	public function init() { 
	
	}
    public function actionIndex() { 
		echo 'Hello World!'; 
	}
	/*public function run(){
		echo 'Hello World!';
	}*/
	public function actionResetUsers($defaultPassword = '123456') {
		$_db = Yii::app()->db;
		$intPage = 1;
		$intRowsPerPage = 1000;
		$intStart = ($intPage-1)*$intRowsPerPage;
		
		//Update Salt
		// echo $defaultPassword;
		$totalUsers = $_db->createCommand("SELECT COUNT(user_id) FROM tbl_users")->queryScalar();
		$objPages=new CPagination($totalUsers);
		$objPages->setCurrentPage($intPage-1);
		$objPages->setPageSize($intRowsPerPage);
		
		$pageCount=$objPages->getPageCount();
		
		//get list users
		for($i=$intPage; $i<=$pageCount; $i++){
			$arrUsers = $_db->createCommand("SELECT * FROM tbl_users LIMIT {$intStart}, {$intRowsPerPage}")->queryAll();
			foreach($arrUsers as $R){
				$secret = Utils::getRandomString(5);
				$salt = Utils::getRandomString(5);
				$hash = md5($defaultPassword.$salt);
				$_db->createCommand("UPDATE tbl_users SET user_salt = '{$salt}', user_password = '{$hash}', user_secret_key = '{$secret}' WHERE user_id = {$R['user_id']}")->execute();
			}
		}
	}
}